package com.zhc.dejingapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhc.dejingapi.common.result.Result;
import com.zhc.dejingapi.common.utils.StringToLocalDateTimeUtils;
import com.zhc.dejingapi.entity.QingZbProcessPlanEntity;
import com.zhc.dejingapi.entity.vo.QingProcessPlanEntityVo;
import com.zhc.dejingapi.mapper.QingZbProcessPlanMapper;
import com.zhc.dejingapi.service.QingZbProcessPlanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author zhc
 * @date 2024年10月08日 10:00
 */
@Service
public class QingZbProcessPlanServiceImpl extends ServiceImpl<QingZbProcessPlanMapper, QingZbProcessPlanEntity> implements QingZbProcessPlanService {

    @Resource
    private StringToLocalDateTimeUtils stringToLocalDateTimeUtils;
    @Resource
    private QingZbProcessPlanMapper qingZbProcessPlanMapper;
    @Override
    public Result addProcessPlan(QingProcessPlanEntityVo qingProcessPlanEntity) {
        QingZbProcessPlanEntity qingZbProcessPlanEntity1 = new QingZbProcessPlanEntity();
        qingZbProcessPlanEntity1.setProductionOrderCode(qingProcessPlanEntity.getProductionOrderCode());
        qingZbProcessPlanEntity1.setMainId(qingProcessPlanEntity.getMainId());
        qingZbProcessPlanEntity1.setPlanStartTime(stringToLocalDateTimeUtils.stringToLocalDateTime(qingProcessPlanEntity.getPlanStartTime()));
        qingZbProcessPlanEntity1.setPlanEndTime(stringToLocalDateTimeUtils.stringToLocalDateTime(qingProcessPlanEntity.getPlanEndTime()));
        qingZbProcessPlanEntity1.setProcessCode(qingProcessPlanEntity.getProcessCode());
        qingZbProcessPlanEntity1.setProcessName(qingProcessPlanEntity.getProcessName());
        qingZbProcessPlanEntity1.setProcessLineNum(qingProcessPlanEntity.getProcessLineNum());
        qingZbProcessPlanEntity1.setCurrentProductionNum(qingProcessPlanEntity.getCurrentProductionNum());
        qingZbProcessPlanEntity1.setFirstOperation(qingProcessPlanEntity.getFirstOperation());
        qingZbProcessPlanEntity1.setLastOpertion(qingProcessPlanEntity.getLastOpertion());
        qingZbProcessPlanEntity1.setSectionCode(qingProcessPlanEntity.getSectionCode());
        qingZbProcessPlanEntity1.setSectionName(qingProcessPlanEntity.getSectionName());
        qingZbProcessPlanEntity1.setWorkCenterCode(qingProcessPlanEntity.getWorkCenterCode());
        qingZbProcessPlanEntity1.setWorkCenterName(qingProcessPlanEntity.getWorkCenterName());
        qingZbProcessPlanEntity1.setInvCode(qingProcessPlanEntity.getInvCode());
        qingZbProcessPlanEntity1.setInvName(qingProcessPlanEntity.getInvName());
        qingZbProcessPlanEntity1.setInvType(qingProcessPlanEntity.getInvType());
        qingZbProcessPlanEntity1.setUnit(qingProcessPlanEntity.getUnit());
        qingZbProcessPlanEntity1.setProcessLineNum(qingProcessPlanEntity.getProcessLineNum());
        qingZbProcessPlanEntity1.setProcessCode(qingProcessPlanEntity.getProcessCode());
        qingZbProcessPlanEntity1.setProcessName(qingProcessPlanEntity.getProcessName());
        qingZbProcessPlanEntity1.setSalesOrderCode(qingProcessPlanEntity.getSalesOrderCode());
        qingZbProcessPlanEntity1.setProcessPlanStatus(qingProcessPlanEntity.getProcessPlanStatus());
        qingZbProcessPlanEntity1.setProcessPlanPriority(qingProcessPlanEntity.getProcessPlanPriority());
        qingZbProcessPlanEntity1.setEquipmentCode(qingProcessPlanEntity.getEquipmentCode());
        qingZbProcessPlanEntity1.setEquipmentName(qingProcessPlanEntity.getEquipmentName());
        qingZbProcessPlanEntity1.setStandardWorkingHour(qingProcessPlanEntity.getStandardWorkingHour());
        qingZbProcessPlanEntity1.setStandardNum(qingProcessPlanEntity.getStandardNum());
        qingZbProcessPlanEntity1.setOrderQuantity(qingProcessPlanEntity.getOrderQuantity());
        qingZbProcessPlanEntity1.setQuantityTran(qingProcessPlanEntity.getQuantityTran());
        qingZbProcessPlanEntity1.setAvailableProduction(qingProcessPlanEntity.getAvailableProduction());
        qingZbProcessPlanEntity1.setProdOrderLineNum(qingProcessPlanEntity.getProdOrderLineNum());
        qingZbProcessPlanEntity1.setProdNum(qingProcessPlanEntity.getProdNum());
        qingZbProcessPlanEntity1.setAcceptanceNum(qingProcessPlanEntity.getAcceptanceNum());
        qingZbProcessPlanEntity1.setDefectiveNum(qingProcessPlanEntity.getDefectiveNum());
        qingZbProcessPlanEntity1.setProdOrderId(qingProcessPlanEntity.getProdOrderId());
        qingZbProcessPlanEntity1.setDispatchNum(qingProcessPlanEntity.getDispatchNum());
        qingZbProcessPlanEntity1.setUsableScrapNum(qingProcessPlanEntity.getUsableScrapNum());
        qingZbProcessPlanEntity1.setUsableAcceptanceNum(qingProcessPlanEntity.getUsableAcceptanceNum());

        int insert = qingZbProcessPlanMapper.insert(qingZbProcessPlanEntity1);


        if (insert > 0){
            return Result.ok(null);
        }else {
            return Result.fail(null);
        }
    }

    @Override
    public Result updateProcessPlan(QingProcessPlanEntityVo qingProcessPlanEntity) {
        QingZbProcessPlanEntity qingZbProcessPlanEntity1 = new QingZbProcessPlanEntity();
        qingZbProcessPlanEntity1.setProductionOrderCode(qingProcessPlanEntity.getProductionOrderCode());
        qingZbProcessPlanEntity1.setMainId(qingProcessPlanEntity.getMainId());
        qingZbProcessPlanEntity1.setPlanStartTime(stringToLocalDateTimeUtils.stringToLocalDateTime(qingProcessPlanEntity.getPlanStartTime()));
        qingZbProcessPlanEntity1.setPlanEndTime(stringToLocalDateTimeUtils.stringToLocalDateTime(qingProcessPlanEntity.getPlanEndTime()));
        qingZbProcessPlanEntity1.setProcessCode(qingProcessPlanEntity.getProcessCode());
        qingZbProcessPlanEntity1.setProcessName(qingProcessPlanEntity.getProcessName());
        qingZbProcessPlanEntity1.setProcessLineNum(qingProcessPlanEntity.getProcessLineNum());
        qingZbProcessPlanEntity1.setCurrentProductionNum(qingProcessPlanEntity.getCurrentProductionNum());
        qingZbProcessPlanEntity1.setFirstOperation(qingProcessPlanEntity.getFirstOperation());
        qingZbProcessPlanEntity1.setLastOpertion(qingProcessPlanEntity.getLastOpertion());
        qingZbProcessPlanEntity1.setSectionCode(qingProcessPlanEntity.getSectionCode());
        qingZbProcessPlanEntity1.setSectionName(qingProcessPlanEntity.getSectionName());
        qingZbProcessPlanEntity1.setWorkCenterCode(qingProcessPlanEntity.getWorkCenterCode());
        qingZbProcessPlanEntity1.setWorkCenterName(qingProcessPlanEntity.getWorkCenterName());
        qingZbProcessPlanEntity1.setInvCode(qingProcessPlanEntity.getInvCode());
        qingZbProcessPlanEntity1.setInvName(qingProcessPlanEntity.getInvName());
        qingZbProcessPlanEntity1.setInvType(qingProcessPlanEntity.getInvType());
        qingZbProcessPlanEntity1.setUnit(qingProcessPlanEntity.getUnit());
        qingZbProcessPlanEntity1.setProcessLineNum(qingProcessPlanEntity.getProcessLineNum());
        qingZbProcessPlanEntity1.setProcessCode(qingProcessPlanEntity.getProcessCode());
        qingZbProcessPlanEntity1.setProcessName(qingProcessPlanEntity.getProcessName());
        qingZbProcessPlanEntity1.setSalesOrderCode(qingProcessPlanEntity.getSalesOrderCode());
        qingZbProcessPlanEntity1.setProcessPlanStatus(qingProcessPlanEntity.getProcessPlanStatus());
        qingZbProcessPlanEntity1.setProcessPlanPriority(qingProcessPlanEntity.getProcessPlanPriority());
        qingZbProcessPlanEntity1.setEquipmentCode(qingProcessPlanEntity.getEquipmentCode());
        qingZbProcessPlanEntity1.setEquipmentName(qingProcessPlanEntity.getEquipmentName());
        qingZbProcessPlanEntity1.setStandardNum(qingProcessPlanEntity.getStandardNum());

        int i = qingZbProcessPlanMapper.updateById(qingZbProcessPlanEntity1);
        if (i > 0){
            return Result.ok(null);
        }else {
            return Result.fail(null);
        }
    }

    @Override
    public Result updateProcessPlan(Long mainId, String planEndTime) {
        QingZbProcessPlanEntity qingZbProcessPlanEntity = new QingZbProcessPlanEntity();
        qingZbProcessPlanEntity.setPlanEndTime(stringToLocalDateTimeUtils.stringToLocalDateTimeYYMMDD(planEndTime));
        QueryWrapper<QingZbProcessPlanEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("main_id",mainId);
        qingZbProcessPlanMapper.update(qingZbProcessPlanEntity,queryWrapper);
        return null;
    }
}
